package zone.haiwen.demo.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import zone.haiwen.demo.domain.dao.TravelMapper;
import zone.haiwen.demo.dto.Passenger;
import zone.haiwen.demo.dto.Travel;
import zone.haiwen.demo.service.TravelService;

import static zone.haiwen.demo.config.TimetableConstant.DATA_LENGTH;

/**
 * Description: 服务实现类
 * @author zhangHaiWen
 * @data 2021/7/7 19:55
 * @return
 **/
@Service
public class TravelServiceImpl extends ServiceImpl<TravelMapper, Travel> implements TravelService {

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:42
     * @return void
     **/
    @Override
    public void createTable() {
        this.baseMapper.createTable();
    }

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:42
     * @return void
     **/
    @Override
    public void insert(Long id, String destination, String passengerName, Long passengerId, String gmtCreate, String gmtModified) {
        for (int i = 0; i < DATA_LENGTH; i++) {
            this.baseMapper.insert(id + i, destination, passengerName, passengerId + i, gmtCreate, gmtModified);
        }
    }

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:42
     * @return com.baomidou.mybatisplus.core.metadata.IPage<zone.haiwen.demo.dto.Travel>
     **/
    @Override
    public IPage<Travel> getTravelByDestination(String destination, Integer current, Integer limit) {
        Page<Travel>  page = new Page<>(current, limit);
        return this.baseMapper.getTravelByDestination(page, destination);
    }

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:42
     * @return com.baomidou.mybatisplus.core.metadata.IPage<zone.haiwen.demo.dto.Travel>
     **/
    @Override
    public IPage<Passenger> leftJoin(Integer current, Integer limit) {
       Page<Passenger> page = new Page<>(current, limit);
       return this.baseMapper.leftJoin(page);
    }


}
